package com.bhs.sansonglogistics.ui.order;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Parcelable;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bhs.sansonglogistics.R;
import com.bhs.sansonglogistics.base.BaseActivity;
import com.bhs.sansonglogistics.bean.FeeDetail;
import com.bhs.sansonglogistics.ui.adapter.FeeDetailAdapter;
import com.bhs.sansonglogistics.utils.LogUtils;
import com.bhs.sansonglogistics.utils.MyUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.math.BigDecimal;
import java.util.ArrayList;

/**
 * 费用明细
 */
public class ObviousCostActivity extends BaseActivity {


    private TextView mTvMoney;
    private TextView mTvOrderType;
    private TextView mTvUnpaidHint;
    private View mView;
    private LinearLayout mLlUnpaidHint;
    private TextView mTvUnpaid;
    private RecyclerView mRvUnpaid;
    private TextView mTvHavePaid;
    private RecyclerView mRvHavePaid;

    private FeeDetailAdapter mAdapter;
    private FeeDetailAdapter mAdapter2;
    private TextView mTvHavePaidHint;
    private View mView2;
    private LinearLayout mLlHavePaid;

    @Override
    public int initLayout() {
        return R.layout.activity_obvious_cost;
    }

    @Override
    public void initView() {
        TextView mTvTitle = findViewById(R.id.tv_title);
        mTvTitle.setText("费用明细");
        mTvMoney = findViewById(R.id.tv_money);
        mTvOrderType = findViewById(R.id.tv_order_type);
        mTvUnpaidHint = findViewById(R.id.tv_unpaid_hint);
        mView = findViewById(R.id.view);
        mLlUnpaidHint = findViewById(R.id.ll_unpaid_hint);
        mTvUnpaid = findViewById(R.id.tv_unpaid);
        mRvUnpaid = findViewById(R.id.rv_unpaid);
        mTvHavePaid = findViewById(R.id.tv_have_paid);
        mRvHavePaid = findViewById(R.id.rv_have_paid);
        mTvHavePaidHint = findViewById(R.id.tv_have_paid_hint);
        mView2 = findViewById(R.id.view2);
        mLlHavePaid = findViewById(R.id.ll_have_paid);
        mAdapter = new FeeDetailAdapter();
        mRvUnpaid.setAdapter(mAdapter);
        mRvUnpaid.setLayoutManager(new LinearLayoutManager(this));
        mAdapter2 = new FeeDetailAdapter();
        mRvHavePaid.setAdapter(mAdapter2);
        mRvHavePaid.setLayoutManager(new LinearLayoutManager(this));
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void initData() {
        int orderType = getIntent().getIntExtra("orderType", 0);
        mTvOrderType.setText(orderType == 1 ? "指派单" : "极速单");
        ArrayList<FeeDetail> unpaid = new ArrayList<>();
        ArrayList<FeeDetail> havePaid = new ArrayList<>();
        ArrayList<FeeDetail> data = getIntent().getParcelableArrayListExtra("FeeDetail");
        BigDecimal sum = new BigDecimal("0");
        BigDecimal bdUnpaid = new BigDecimal("0");
        BigDecimal bdHavePaid = new BigDecimal("0");
        for (FeeDetail datum : data) {
            sum = sum.add(new BigDecimal(datum.getMoney()));
            if (datum.getStatus() == 0) {
                unpaid.add(datum);
                bdUnpaid = bdUnpaid.add(new BigDecimal(datum.getMoney()));
            }
            if (datum.getStatus() == 2) {
                havePaid.add(datum);
                bdHavePaid = bdHavePaid.add(new BigDecimal(datum.getMoney()));
            }
        }
        mTvMoney.setText(sum.toString());
        if (MyUtils.isEmpty(unpaid)) {
            mTvUnpaidHint.setVisibility(View.GONE);
            mLlUnpaidHint.setVisibility(View.GONE);
            mView.setVisibility(View.GONE);
            mRvUnpaid.setVisibility(View.GONE);
        } else {
            mAdapter.setNewData(unpaid);
            mTvUnpaid.setText(bdUnpaid.toString());
        }

        if (MyUtils.isEmpty(havePaid)) {
            mTvHavePaidHint.setVisibility(View.GONE);
            mLlHavePaid.setVisibility(View.GONE);
            mView2.setVisibility(View.GONE);
            mRvHavePaid.setVisibility(View.GONE);
        } else {
            mAdapter2.setNewData(havePaid);
            mTvHavePaid.setText(bdHavePaid.toString());
        }
    }
}